import java.util.Scanner;
class SequentialQueue {
    private int[] queue;  // 队列的存储数组
    private int front;  // 队列头指针
    private int rear;   // 队列尾指针
    private int size;    // 当前队列中的元素数量
    private int length;  // 队列的最大容量
    public SequentialQueue(int length) {
        this.length = length;
        this.queue = new int[length];
        this.front = 0;
        this.rear = -1;
        this.size = 0;
    }
    public boolean isFull() {    // 判断队列是否已满
        return size == length;
    }
    public boolean isEmpty() {     // 判断队列是否为空
        return size == 0;
    }
    public void enqueue(int data) {  // 入队操作
        if (isFull()) {
            System.out.println("队列已满");
            return;
        }
        rear++;
        queue[rear] = data;
        size++;
        System.out.println("入队成功");
    }
    public int dequeue() {    // 出队操作
        if (isEmpty()) {
            System.out.println("队列为空");
            return -1;
        }
        int removedData = queue[front];
        front++;
        size--;
        System.out.println("出队成功");
        return removedData;
    }
    public int peek() {   // 查看队列首元素
        if (isEmpty()) {
            System.out.println("队列为空");
            return -1;
        }
        return queue[front];
    }
    public String toString() {
        if (isEmpty()) {
            return "队列为空";
        }
        StringBuilder sb = new StringBuilder();
        for (int i = front; i <= rear; i++) {
            sb.append(queue[i]).append(" ");
        }
        return sb.toString();
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入顺序队列的大小:");
        int length = sc.nextInt();
        SequentialQueue queue = new SequentialQueue(length);
        while (true) {
            System.out.println("请输入操作类型（1: 入队, 2: 出队, -1: 结束操作）:");
            int work = sc.nextInt(); // 读取用户输入的操作类型
            if (work == -1) { // 如果输入-1，结束操作
                break;
            } else if (work == 1) { // 如果输入1，进行入队操作
                System.out.println("请输入入队列的元素值（输入-1结束入队）:");
                while (true) {
                    int data = sc.nextInt(); // 读取用户输入的元素
                    if (data == -1) { // 如果输入-1，结束入队操作
                        break;
                    }
                    queue.enqueue(data); // 将元素入队
                    System.out.println("队列当前元素值: " + queue);
                }
            } else if (work == 2) { // 如果输入2，进行出队操作
                int removedData = queue.dequeue(); // 将元素出队
                if (removedData != -1) {
                    System.out.println("元素 " + removedData + " 出队成功");
                }
                System.out.println("队列当前元素值: " + queue);
            } else {
                System.out.println("无效的操作，请输入1, 2 或 -1");
            }
        }
        if (!queue.isEmpty()) {
            System.out.println("当前队列首元素为: " + queue.peek());
        } else {
            System.out.println("队列为空");
        }
        sc.close();
    }
}

